package com.tongtailian.www.stir.bean;

import com.tongtailian.www.stir.utils.LogUtil;

import androidx.annotation.NonNull;

/**
 * @author liuml
 * @explain 物理按键
 * @time 2020/10/11 12:53
 */
public class DeviceKeyFram extends BaseDataFram {

    public DeviceKeyFram(String param, String data) {
        this.type = BaseDataFramType.devicesKey;
        this.param = param;
        this.data = data;
//        super("70", param, data);
    }


    @Override
    public void parseFrame(String frame) {
        super.parseFrame(frame);
        int position = 0;
        //具体解析
        LogUtil.d("解析数据:" + data);
//        name = parseIntResult(position, data2);
//
//        position = position + data2;
//        Flow = parseIntResult(position, data2);
//
//        position = position + data2;
//        Step = parseIntResult(position, data2);
//
//        position = position + data2;
//        DataDev = parseIntResult(position, data2);
    }


    public static String encode(String str) {
        //根据默认编码获取字节数组
        byte[] bytes = str.getBytes();
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        //将字节数组中每个字节拆解成2位16进制整数
        for (int i = 0; i < bytes.length; i++) {
            sb.append(hexString.charAt((bytes[i] & 0xf0) >> 4));
            sb.append(hexString.charAt((bytes[i] & 0x0f) >> 0));
        }
        return sb.toString();
    }

    private static String hexString = "0123456789ABCDEF";

    /**
     * 十六进制转换字符串
     *
     * @return String 对应的字符串
     */
    public static String hexStr2Str(String hexStr) {
        String str = "0123456789ABCDEF";
        char[] hexs = hexStr.toCharArray();
        byte[] bytes = new byte[hexStr.length() / 2];
        int n;

        for (int i = 0; i < bytes.length; i++) {
            n = str.indexOf(hexs[2 * i]) * 16;
            n += str.indexOf(hexs[2 * i + 1]);
            bytes[i] = (byte) (n & 0xff);
        }
        return new String(bytes);
    }


    public String bytes2String(byte[] data) {
        String getString = "";
        for (int i = 0; i < data.length; i++) {
            getString += String.format("%02X", data[i]);

        }
        return getString;

    }

    @NonNull
    @Override
    public String toString() {
        return super.toString();
    }
}
